﻿/**
 * Sprite
 * 
 * @version 2012.01.27
 * @author  Bruno Miguel de Oliveira Tamer <bmotamer@gmail.com>
 */

#region XNA Libraries

using Microsoft.Xna.Framework.Graphics;

#endregion

namespace main.sdk.display.object2d
{

    public class Sprite : Object2D
    {

        #region Instance Variables

        private Texture2D _Texture;

        public Texture2D Texture
        {
            get { return _Texture; }
            set
            {
                _Texture = value;
                SourceRectangle.X = 0;
                SourceRectangle.Y = 0;
                if (_Texture != null)
                {
                    SourceRectangle.Width  = _Texture.Width;
                    SourceRectangle.Height = _Texture.Height;
                }
            }
        }

        public string AssetName
        {
            get { return _Texture == null ? null : _Texture.Name; }
            set { Texture = Program.Self.Content.Load<Texture2D>(value); }
        }

        #endregion

        #region Constructor & Destructor

        public Sprite(Texture2D texture = null) { Texture = texture; }

        public Sprite(string assetName) { Texture = Program.Self.Content.Load<Texture2D>(assetName); }

        public override void Dispose()
        {
            base.Dispose();
            Texture = null;
        }

        #endregion

        #region Drawing

        public override void Draw(SpriteBatch spriteBatch)
        {
            if (_Texture == null)
                return;
            spriteBatch.Draw(_Texture, Position, SourceRectangle, Color * _Alpha, Rotation, Origin, Scale, Effects, LayerDepth);
        }

        #endregion

    }

}